package com.asman.vr.dto

import androidx.annotation.MainThread
import com.asman.vr.network.Api
import com.asman.vr.network.ApiWorker
import com.asman.vr.network.RequestBody
import com.asman.vr.network.liveData
import java.util.concurrent.Executor

class AccountRepository(
        private val api: Api,
        private val apiWorker: ApiWorker,
        private val networkExecutor: Executor
) {

    @MainThread
    fun wxLogin(code: String) = liveData(api.wxLogin(RequestBody.Code(code)))

    @MainThread
    fun sendSmsCode(phoneNumber: String, type: Int) =
        liveData(api.sendSmsCode(RequestBody.PhoneNumber(phoneNumber, type)))

    @MainThread
    fun loginByPhoneNumber(phoneNumber: String, code: String) =
        liveData(api.loginByPhoneNumber(RequestBody.PhoneAndCode(phoneNumber, code)))

    @MainThread
    fun othersBindPhone(channelUserToken: String, phoneNumber: String, code: String) =
        liveData(api.othersBindPhone(RequestBody.BindPhone(channelUserToken, phoneNumber, code)))

    @MainThread
    fun phoneBindOthers(channelUserToken: String) =
        liveData(api.phoneBindOthers(RequestBody.BindWX(channelUserToken)))

    @MainThread
    fun getUserInfo() = liveData(api.getUserInfo())

    @MainThread
    fun changePhoneNumber(phoneNumber: String, code: String) = liveData(
        api.changePhoneNumber(RequestBody.PhoneAndCode(phoneNumber, code))
    )

    @MainThread
    fun getUserRoleInfo() = liveData(api.getUserRoleInfo())

    @MainThread
    fun chooseEnterprise(enterpriseId: Long) = liveData(apiWorker.chooseEnterprise(enterpriseId))
}